/**********************************************************************
 *
 * Filename:    log.c  v0.1
 * 
 * Description: log.
 *
 * Notes:
 *		.
 *
 **********************************************************************/
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <time.h>
#include "log.h"

static int log_level=0;
void log_init(int level)
{
	log_level=level;
}
int LOG(int level, const char *fmt, ...)
{
	time_t current;
	struct tm *t;
	static char buf[1000];
	int i;
	va_list args;

	if(level>log_level){
		return 0;
	}
	va_start(args, fmt);
	i = vsprintf(buf, fmt, args);
	va_end(args);

	time(&current);
	t=localtime(&current);
	printf("[%04d-%02d-%02d %02d:%02d:%02d]%s\n", t->tm_year+1900,t->tm_mon+1,t->tm_mday, 
		t->tm_hour,t->tm_min, t->tm_sec,
		buf);
	return 0;
}
